import React, { useState, useEffect } from 'react'

function App() {
  const [ proList, setProList ] = useState([])
  // useEffect 内部返回一个函数, 返回的函数相当于 componentWillUnmount
  // useEffect(() => { return () => {}})
  useEffect(() => {
    fetch('http://121.89.205.189/api/pro/list').then(res => res.json())
      .then(res => {
        console.log(res.data)
        setProList(res.data)
      })

      return () => { // componentWillUnmount 需要时再写

      }
  }, [])

  return (
    <div>
      {
        proList && proList.map(item => {
          return (
          <div key = { item.proid }>{ item.proname }</div>
          )
        })
      }
    </div>
  )
}

export default App
